using UnityEngine;
using System.Collections;

public class BlocAnimator : MovingElement {


	public Texture2D Texture1;
	public Texture2D Texture2;
	public Texture2D Texture3;
	
	public float TimeForChange;
	
	
	private Texture2D[] mTextures = new Texture2D[3];
	private float mLastTime = 0;
	
	new protected void Start()
	{
		base.Start();
		
		mTextures[0] = Texture1;
		mTextures[1] = Texture2;
		mTextures[2] = Texture3;
		
		TimeForChange = 0.05f;
		mLastTime = 0;
		
		renderer.material.mainTexture = mTextures[Random.Range(0,3)];
	}
	
	// Update is called once per frame
	protected void Update () 
	{
		
		mLastTime += Time.deltaTime;
		
		if(mLastTime > TimeForChange)
		{
			mLastTime = 0;
			ChangeEffect();
		}
	}
	
	private void ChangeEffect()
	{
		int lEffect = Random.Range(0,3);
		
		switch(lEffect)
		{
		case 0:
				transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
				break;
		case 1:
				transform.localScale = new Vector3(transform.localScale.x, -transform.localScale.y, transform.localScale.z);
				break;
		case 2:
				renderer.material.mainTexture = mTextures[Random.Range(0,3)];
				break;
		default:
			break;
		}
	}
}
